package leetcode.editor.cn;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Administrator
 * @description 1338. 数组大小减半
 * @date 25
 */
public class Solution1338 {
    public int minSetSize(int[] arr) {
        Map<Integer, Integer> out = new HashMap();
        int len = arr.length / 2;
        int sum = 0, num = 0;
        for (int i : arr) {
            out.put(i, out.getOrDefault(i, 0)+1);
        }
        List<Integer> objects = out.values().stream().sorted(Integer::compare).collect(Collectors.toList());
        for (Integer i : objects) {
            sum += i;
            num++;
            if (sum > len) {
                break;
            }
        }
        return num;
    }
}
